package com.etc.service.impl;

import java.util.List;

import com.etc.entity.AsUser;
import com.etc.mapper.AsUserMapper;
import com.etc.service.IAsUserService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.ruoyi.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 测试Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-11-25
 */
@Service
public class AsUserServiceImpl implements IAsUserService
{
    @Autowired
    private AsUserMapper asUserMapper;

    /**
     * 查询测试
     * 
     * @param id 测试主键
     * @return 测试
     */
    @Override
    public AsUser selectAsUserById(Long id)
    {
        return asUserMapper.selectAsUserById(id);
    }

    /**
     * 查询测试列表
     * 
     * @param
     * @return 测试
     */
    @Override
    public Page<AsUser> selectAsUserList(String keywords, int  page, int limit)
    {
        PageHelper.startPage(page,limit);
        List<AsUser> asUsers = asUserMapper.selectAsUserList("%"+keywords+"%");
        return (Page<AsUser>) asUsers;
    }

    /**
     * 新增测试
     * 
     * @param asUser 测试
     * @return 结果
     */
    @Override
    public int insertAsUser(AsUser asUser)
    {
        AsUser asUser1 = asUserMapper.selectAsUserByPhone(asUser);
        if (asUser1!=null){
            return 0;
        }
        return asUserMapper.insertAsUser(asUser);
    }

    /**
     * 修改测试
     * 
     * @param asUser 测试
     * @return 结果
     */
    @Override
    public int updateAsUser(AsUser asUser)
    {
        return asUserMapper.updateAsUser(asUser);
    }

    /**
     * 批量删除测试
     * 
     * @param ids 需要删除的测试主键
     * @return 结果
     */
    @Override
    public int deleteAsUserByIds(Long[] ids)
    {
        return asUserMapper.deleteAsUserByIds(ids);
    }

    /**
     * 删除测试信息
     * 
     * @param id 测试主键
     * @return 结果
     */
    @Override
    public int deleteAsUserById(Long id)
    {
        return asUserMapper.deleteAsUserById(id);
    }

    @Override
    public AjaxResult selectAsUserLogin(AsUser user) {
        AsUser asUser = asUserMapper.selectAsUserByPhone(user);
        if (asUser==null){
            return AjaxResult.success("未注册账号");
        }
        AsUser asUserLogin = asUserMapper.selectAsUserLogin(user);
        if (asUserLogin==null){
            return AjaxResult.success("密码错误");
        }
        return AjaxResult.success(asUserLogin);

    }

    @Override
    public AsUser selectAsUserByPhone(AsUser user) {
        return null;
    }
}
